import java.io.FileOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;


public class ServerNhanUDP {
	public static void main(String[] args) throws IOException{
		FileOutputStream fos=new FileOutputStream("F:/file1.rar");
		DatagramSocket serverSK=new DatagramSocket(9090);
		while(true)
		{
			byte[]buf=new byte[1024];
			DatagramPacket serverPK=new DatagramPacket(buf, buf.length);
			serverSK.receive(serverPK);
			byte[]buf_nhan=serverPK.getData();
			System.out.println(buf_nhan.toString());
			if((new String(buf_nhan)).contains("end"))
				break;
			fos.write(buf_nhan);
			fos.close();
		}
		System.out.println("Server nhan thanh cong...");
		serverSK.close();
	}
}
